package com.szholly.pro.watergas_server.ps.controller;

import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.codec.binary.Base64;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.szholly.pro.watergas_server.common.web.BaseController;
import com.szholly.pro.watergas_server.common.web.WebContext;
import com.szholly.plug.form.excel.utils.StringUtil;


@Controller
@RequestMapping("/Echar/")
public class EcharController  extends BaseController { 
	//保存图片
	@RequestMapping(value = "/saveImages")
	public void saveImages(HttpServletRequest resq, HttpServletResponse res) throws Exception {
        String ImgData = resq.getParameter("imageData");  
        String ParmName = resq.getParameter("ParmName");
        String MN = resq.getParameter("MN");
        if(StringUtil.IsNullOrEmpty(ImgData)) {
        	return;
        }
        if(StringUtil.IsNullOrEmpty(ParmName)) {
        	return;
        }
        if(StringUtil.IsNullOrEmpty(MN)) {
        	return;
        }
        try {  
            String[] url = ImgData.split(",");  
            String image = url[1];  
            // Base64解码  
			byte[] imageByte = new Base64().decode(image);    
            // 生成图片  
			String path = WebContext.getServerPath();
            OutputStream out = new FileOutputStream(new File(path+"\\reportChar\\"+MN+"-"+ParmName+".png"));  
            out.write(imageByte);  
            out.flush();  
            out.close();  
          
        } catch (Exception e) {  
            e.printStackTrace();  
        } 
	}
}
